#include <bits/stdc++.h>
using namespace std;
int n, s, a[10010];
int x[101][101];
int d[101], top, maxn, p[10010];
int b[10010];
vector<int>m;
void dfs(int cur)
{
	for(int i = cur - 1; i <= s; i++)
	{
		cout << i << endl;
		d[++top] = i;
		for(int j = 1; j <= n; j++){
			m[j] += x[i][j];
		}
		bool l = 0;
		for(int j = 1; j <= n; j++)
		{
			if(m[j] < a[j])
			{
				l = 1;
				break;
			}
		}
		if(l == 0 && top < maxn)
		{
			for(int j = 1; j <= top; j++)
			{
				memset(p, 0, maxn);
				p[j] = d[j];
				maxn = top;
			}
		}
		else if(cur + 1 < maxn)
			dfs(cur + 1);
		
		d[top] = 0;
		top--;
		for(int j = 1; j <= n; j++)
			m[j] -= x[i][j];
	}
}
int main()
{
	cin >> n;
	for(int i = 1; i <= n;  i++)
		cin >> a[i];
	cin >> s;
	for(int i = 1; i <= s; i++)
		for(int j = 1; j <= n; j++)
			cin >> x[i][j];
	dfs(1);
	cout << maxn << " ";
	for(int i = 1; i <= maxn; i++)
		cout << p[i] << " ";
	return 0;
}
/*4
100 200 300 400
3
50 50 50 50
200 300 200 300
900 150 389 399
*/